package com.billdowney.util.microsoft.office.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @ClassName: ExcelUtil
 * @Description: excel表格工具类
 * @author 超级小富翁 - BillDowney
 * @date 2018年5月18日 上午11:03:15
 */
public class ExcelUtil {

	/**
	 * excel格式xls
	 */
	private static final String EXCEL_XLS = "xls";
	/**
	 * excel格式xlsx
	 */
	private static final String EXCEL_XLSX = "xlsx";

	public static Workbook getWorkbook(File file) throws IOException {
		Workbook wb = null;
		FileInputStream in = new FileInputStream(file);
		if (file.getName().endsWith(EXCEL_XLS)) { // Excel 2003
			wb = new HSSFWorkbook(in);
		} else if (file.getName().endsWith(EXCEL_XLSX)) { // Excel 2007/2010
			wb = new XSSFWorkbook(in);
		}
		return wb;
	}
}
